<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>鸿博租房有限公司</title>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/layui/layui.js"></script>
    <script src="/js/jquery-1.8.3.js"></script>
</head>
<body class="layui-layout-body"><!-- background="/imgs/123.jpg" -->

<form class="layui-form" onsubmit="return region()">
  <input type="hidden" name="_token" value="{{ csrf_token() }}" id="_token">
  <div class="layui-form-item">
    <label class="layui-form-label">用户名框</label>
    <div class="layui-input-inline">
      <input type="user_name" name="user_name" id="user_name" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input" onblur="name_z()">
      <span id="name_s"></span>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">密码框</label>
    <div class="layui-input-inline">
      <input type="password" name="user_pwd" id="user_pwd" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" onblur="pwd_z()">
      <span id="pwd_s"></span>
    </div>
  </div>


  <div class="layui-inline">
      <label class="layui-form-label">邮箱</label>
      <div class="layui-input-inline">
        <input type="text" name="user_email" id="user_email" lay-verify="user_email" autocomplete="off" class="layui-input" placeholder="请输入邮箱" onblur="email_z()">
        <span id="email_s"></span>
      </div>
    </div>
  </div>
<br><br>
 <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">手机号</label>
      <div class="layui-input-inline">
        <input type="user_tel" name="user_tel" id="user_tel" lay-verify="required|user_tel" autocomplete="off" class="layui-input" placeholder="请输入手机号" onblur="tel_z()">
        <span id="tel_s"></span>
      </div>
    </div>
	 <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">用户组</label>
      <div class="layui-input-inline">
      	<select name="g_id" id="g_id">
			<option value="1">超级管理员</option>
			<option value="2">物业公司</option>
			<option value="3">销售人员</option>
			<option value="4">用户</option>
      	</select>
      </div>
    </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo" onclick="region()">添加</button>
      
    </div>
  </div>
</form>
<a href="{{url('index/introduce')}}">返回</a>
<script>
function tel_z(){
  var tel_z = /^1[34578]\d{9}$/;
  var user_tel = $('#user_tel').val();
  if(user_tel.length == 0){
    $('#tel_s').html("<font color='red'>手机号不能为空</font>");
    return false;
  }else{
    if(tel_z.test(user_tel)){
      $('#tel_s').html("<font color='green'>手机号格式正确</font>");
      return true;
    }else{
      $('#tel_s').html("<font color='red'>手机号不能多余11位和少于11位</font>");
      return false;
    }
  }
}  


function email_z(){
  var email_z = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  var user_email = $('#user_email').val();
  if(user_email.length == 0){
    $('#email_s').html("<font color='red'>邮箱名不能为空</font>");
    return false;
  }else{
    if(email_z.test(user_email)){
      $('#email_s').html("<font color='green'>邮箱格式正确</font>");
      return true;
    }else{
      $('#email_s').html("<font color='red'>请输入正确的邮箱后面加上@qq.com</font>");
      return false;
    }
  }

}
function pwd_z(){
   var pwd_z = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
   var user_pwd = $('#user_pwd').val();
   if(user_pwd.length == 0){
    $('#pwd_s').html("<font color='red'>密码名不能为空</font>");
    return false;
   }else{
     if(pwd_z.test(user_pwd)){
        $('#pwd_s').html("<font color='green'>密码格式正确</font>");
        return true;
     }else{
        $('#pwd_s').html("<font color='red'>密码最少6位，包括至少1个大写字母，1个小写字母，1个数字，1个特殊字符</font>");
        return false;
     }
   }
}

function name_z(){
  var name_z = /^[a-zA-Z0-9_-]{4,16}$/;
  var user_name = $('#user_name').val();
  if(user_name.length == 0){
    $('#name_s').html("<font color='red'>用户名不能为空</font>");
    return false;
  }else{
    if(name_z.test(user_name)){
      $('#name_s').html("<font color='green'>用户名格式正确</font>");
      return true;
    }else{
      $('#name_s').html("<font color='red'>请输入4到6位的用户名</font>");
      return false;
    }
  }
}

function region(){
/*    if(name_z()==false && pwd_z() == false && email_z() == false && tel_z() == false){
      return false;
    }*/
    var gm_name  = $('#user_name').val();
    var gm_pwd   = $('#user_pwd').val();
    var gm_email = $('#user_email').val();
    var gm_tel   = $('#user_tel').val();
    var _token      = $('#_token').val();
    var g_id = $('#g_id').val();
   // alert(g_id);die;
    var data = new FormData();

    data.append('gm_name',gm_name);
    data.append('gm_pwd',gm_pwd);
    data.append('gn_email',gn_email);
    data.append('gm_tel',gm_tel);
    data.append('g_id',g_id);
    data.append('_token',_token);

   $.ajax({
          type: "POST",
          url: "{{url('index/add_do')}}",
          data: data,
          cache: false,
          processData: false,
          contentType: false,
          success: function(msg){
              if(msg ==1){
                alert('添加成功！')
                window.location.href="{{url('index/list')}}";
              }else{
                alert(添加失败)
                window.location.href="{{url('index/add')}}";
              }
          }
      });

}
//Demo
layui.use('form', function(){
  var form = layui.form;
  
  //监听提交
  form.on('submit(formDemo)', function(data){
    //layer.msg(JSON.stringify(data.field));
    return false;
  });
});
</script>

</body>
</html>